package com.hp.controller;

import com.hp.annotation.Power;
import com.hp.entity.Message;
import com.hp.result.DataGridResultInfo;
import com.hp.result.SubmitResultInfo;
import com.hp.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Power(name = "留言管理",type =0)
@Controller
@RequestMapping("/msg")
public class MessageController {

	@Autowired
	private MessageService messageService;
	@Power(name = "去留言页面",type =1,url = "/msg/querymessage")
	@RequestMapping("/querymessage")
	public String querymessage(){
		return "msg/querymessage";
	}
	@Power(name = "查询留言数据",type =1,url = "/msg/querymessage_result")
	@ResponseBody
	@RequestMapping("/querymessage_result")
	public DataGridResultInfo querymessage_result(@RequestParam(name = "page", defaultValue = "1") int page,
												  @RequestParam(name = "rows", defaultValue = "10") int rows) throws Exception {
		
		return messageService.findAll(page,rows);
	}

	@Power(name = "删除留言数据",type =1,url = "/msg/deletemsg")
	@ResponseBody
	@RequestMapping(value="/deletemsg",method=RequestMethod.POST)
	public SubmitResultInfo deletemsg(String id) throws Exception {
		return messageService.deletemsg(id);
	}
	@Power(name = "显示/隐藏留言",type =1,url = "/msg/updatestatus")
	@ResponseBody
	@RequestMapping(value="/updatestatus",method=RequestMethod.POST)
	public SubmitResultInfo updatestatus(String id) throws Exception {
		 Message message=new Message();
		 String[] str = id.split(",");
		 message.setId(str[0]);
		 message.setStatus(Integer.parseInt(str[1]));
		return messageService.updatestatus(message);
	}
	@Power(name = "查看留言信息",type =1,url = "/msg/lookmsg")
	@RequestMapping("lookmsg")
	public String lookmsg(String id,Model model) throws Exception {
	  Message msg=	messageService.findById(id);
	  model.addAttribute("msg", msg);
	  return "msg/lookmessage";
	}
}
